﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LTJ.Common;
using LTJ.Entity;
using LTJ.FrameWork;
using System.Data;

namespace uswinweb.admin
{
    public partial class routesList_add : AdminPage
    {
        protected int cid = SASRequest.GetInt("cid", 0);
        protected string ids = SASRequest.GetString("ids");

        protected void Page_Load(object sender, EventArgs e)
        {
            if (SASRequest.IsPost())
            {
                AddRoutes();
            }
        }

        protected void AddRoutes()
        {
            string routesCode = SASRequest.GetFormString("routes_hidd_luffy");
            string shipcompCode = SASRequest.GetFormString("shipcomp_hidd_luffy");
            DataTable dt = new DataTable();
            dt.Columns.Add("cid", typeof(string));
            dt.Columns.Add("tcode", typeof(string));
            dt.Columns.Add("tname", typeof(string));
            dt.Columns.Add("bcode", typeof(string));
            dt.Columns.Add("bname", typeof(string));
            dt.Columns.Add("creater", typeof(string));
            string[] code = ids.Split(',');
            for (int i = 0; i < code.Length; i++)
            {
                DataRow newdr = dt.NewRow();
                newdr["cid"] = cid;
                newdr["tcode"] = code[i];
                newdr["tname"] = "";
                newdr["bcode"] = shipcompCode;
                newdr["bname"] = "";
                newdr["creater"] = username;
                dt.Rows.Add(newdr);
            }
            int msg = Routes.AddRoute(dt);
            if (msg > 0)
            {
                base.RegisterStartupScript("PAGE", "parent.document.getElementById('reclick').click();parent.Lightview.hide();");
            }
            else
            {
                if (msg == -1)
                {
                    base.RegisterStartupScript("PAGETEMPLATE", "此航线已存在！");
                }
                base.RegisterStartupScript("PAGETEMPLATE", "航线添加失败!");
            }
        }
    }
}